package com.ruoyi.web.controller.eamp;

import com.ruoyi.common.annotation.IEampSrAddLog;
import com.ruoyi.common.annotation.IEampSrRemoveLog;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.eamp.domain.EampSrMan;
import com.ruoyi.eamp.service.IEampSrManService;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 库房管理
Controller
 * 
 * @author ruoyi
 * @date 2024-08-08
 */
@RestController
@RequestMapping("/eamp/sr_man")
public class EampSrManController extends BaseController
{
    @Autowired
    private IEampSrManService eampSrManService;

    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询库房管理列表
     */
    @PreAuthorize("@ss.hasPermi('eamp:sr_man:list')")
    @GetMapping("/list")
    public TableDataInfo list(EampSrMan eampSrMan)
    {
        startPage();
        List<EampSrMan> list = eampSrManService.selectEampSrManList(eampSrMan);
        return getDataTable(list);
    }
    /**
     * 导出库房管理列表
     */
    @PreAuthorize("@ss.hasPermi('eamp:sr_man:export')")
//    @Log(title = "库房管理 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EampSrMan eampSrMan)
    {
        List<EampSrMan> list = eampSrManService.selectEampSrManList(eampSrMan);
        ExcelUtil<EampSrMan> util = new ExcelUtil<EampSrMan>(EampSrMan.class);
        util.exportExcel(response, list, "库房管理数据");
    }

    /**
    * 查询用户列表listUser
     * */
    @GetMapping("/listUser")
    public TableDataInfo listUser()
    {
        SysUser sysUser = new SysUser();
        List<SysUser> list = sysUserService.selectUserList(sysUser);
        return getDataTable(list);
    }
    /**
    * 获取不分页所有库房列表srAllList
     * */
    @GetMapping("/srAllList")
    public TableDataInfo srAllList()
    {
        EampSrMan eampSrMan = new EampSrMan();
        eampSrMan.setDelFlg(1L);
        List<EampSrMan> list = eampSrManService.selectEampSrManList(eampSrMan);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('eamp:sr_man:query')")
    @GetMapping(value = "/{srId}")
    public AjaxResult getInfo(@PathVariable("srId") Long srId)
    {
        return success(eampSrManService.selectEampSrManBySrId(srId));
    }

    /**
     * 新增库房管理

     */
    @PreAuthorize("@ss.hasPermi('eamp:sr_man:add')")
//    @Log(title = "库房管理 ", businessType = BusinessType.INSERT)
    @PostMapping
    @IEampSrAddLog
    public AjaxResult add(@RequestBody EampSrMan eampSrMan)
    {
        Long userId = SecurityUtils.getUserId();
        LocalDateTime dateTime = LocalDateTime.now();
        eampSrMan.setSrCreateTime(dateTime);
        eampSrMan.setSrCreateBy(userId);
        eampSrMan.setSrCurrentSpecifications(eampSrMan.getSrSpecification());
        eampSrMan.setSrState(0l);
        eampSrMan.setDelFlg(1L);
        return toAjax(eampSrManService.insertEampSrMan(eampSrMan));
    }

    /**
     * 修改库房管理

     */
    @PreAuthorize("@ss.hasPermi('eamp:sr_man:edit')")
//    @Log(title = "库房管理 ", businessType = BusinessType.UPDATE)
    @PutMapping
    @IEampSrAddLog
    public AjaxResult edit(@RequestBody EampSrMan eampSrMan)
    {
        return toAjax(eampSrManService.updateEampSrMan(eampSrMan));
    }

    /**
     * 删除库房管理

     */
    @PreAuthorize("@ss.hasPermi('eamp:sr_man:remove')")
//    @Log(title = "库房管理 ", businessType = BusinessType.UPDATE)
	@DeleteMapping("/{srIds}")
    @IEampSrRemoveLog
    public AjaxResult remove(@PathVariable Long[] srIds)
    {
        return toAjax(eampSrManService.deleteEampSrManBySrIds(srIds));
    }
}
